<template>
    <fieldset>
        <legend>Cart</legend>
        <h1>{{name}}</h1>
        <ul>
            <li v-for="item in carts" :key="item.id">
                <b>商品:{{item.title}}</b>
                --
                <b>价格:{{item.price}}</b>
                --
                <b>数量:{{item.count}}</b>
                --
                <button @click="remove(item)">移除购物车</button>
            </li>
        </ul>
        <h1 style="text-align:right">
            <b>总价格:</b>
            <b style="color:red">{{total}}</b>
        </h1>
    </fieldset>
</template>
<script>
    import { mapState, mapGetters, mapActions } from "vuex"
    export default {
        computed: {
            ...mapState("Cart", ['name', 'carts']),
            ...mapGetters("Cart", ['total'])

        },
        methods: {
            ...mapActions('Cart', ['REMOVE_CART']),
            remove(item) {
                this.REMOVE_CART(item)
            }
        },
    }
</script>